import { PageDto } from "../models/page.model";
import { UaCard, UaCardSearchRequest } from "../models/ua-card.model";
import { GlobalService } from "./global.service";


export class UaCardService {
  static PATH = "/ua/card";
  static findListByIpId(ipId: number) {
    return new Promise<UaCard[]>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}${UaCardService.PATH}/findZhDtoByIpId/${ipId}`,
          method: "GET",
          success: (response) => resolve(response.data as UaCard[]),
          fail: (err) => reject(err)
        });
      }
    )
  }

  static searchWithPage(searchRequest: UaCardSearchRequest, page: number) {
    return new Promise<PageDto<UaCard>>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}${UaCardService.PATH}/searchDto?size=21&page=${page}`,
          data: searchRequest,
          method: "POST",
          success: (response) => resolve(response.data as PageDto<UaCard>),
          fail: (err) => reject(err)
        });
      }
    )
  }

  static ap() {
    return new Promise<UaCard[]>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}${UaCardService.PATH}/ap`,
          method: "GET",
          success: (response) => resolve(response.data as UaCard[]),
          fail: (err) => reject(err)
        });
      }
    )
  }
  static findByCardId(cardId: number) {
    return new Promise<UaCard>(
      (resolve, reject) => {
        wx.request({
          url: `${GlobalService.HOST}${UaCardService.PATH}/findBy/${cardId}`,
          method: "GET",
          success: (response) => resolve(response.data as UaCard),
          fail: (err) => reject(err)
        });
      }
    )
  }
}
